<?php

/**
 * This is the model class for table "tbl_software".
 *
 * The followings are the available columns in table 'tbl_software':
 * @property string $id
 * @property string $name
 * @property string $description
 * @property string $technical
 * @property string $change_log
 * @property integer $cate_id
 * @property integer $status
 * @property integer $type
 */
class Software extends CActiveRecord {
    const STATUS_PUBLISHED =1;
    const UNSTATUS_PUBLISHED =0;

    /**
     * Returns the static model of the specified AR class.
     * @return Software the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'tbl_software';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('name', 'required'),
            array('cate_id, status, type', 'numerical', 'integerOnly' => true),
            array('name', 'length', 'max' => 255),
            array('description, technical, change_log', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, name, description, technical, change_log, cate_id, status, type', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'version'=>array(self::HAS_MANY, 'tbl_version', 'sw_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'name' => 'Name',
            'description' => 'Description',
            'technical' => 'Technical',
            'change_log' => 'Change Log',
            'cate_id' => 'Cate',
            'status' => 'Status',
            'type' => 'Type',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('name', $this->name, true);
        $criteria->compare('description', $this->description, true);
        $criteria->compare('technical', $this->technical, true);
        $criteria->compare('change_log', $this->change_log, true);
        $criteria->compare('cate_id', $this->cate_id);
        $criteria->compare('status', $this->status);
        $criteria->compare('type', $this->type);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}